package com.prs.crm.dao.oa.bookmanager.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.oa.bookmanager.BookRegisterDao;
import com.prs.crm.domain.oa.bookmanager.BookRegister;

public class BookRegisterDaoImpl extends BaseDaoImpl<BookRegister> implements BookRegisterDao{

	@SuppressWarnings("unchecked")
	@Override
	public List<BookRegister> getAllBookRegister() {
		return (List<BookRegister>) this.getHibernateTemplate().execute(new HibernateCallback() {
			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				Criteria criteria=session.createCriteria(BookRegister.class);
				return criteria.list();
			}
		});
	}

	@SuppressWarnings("unchecked")
	@Override
	public BookRegister getBookRegisterByName(final String name) {
		Criteria criteria=this.getSession().createCriteria(BookRegister.class);
		criteria.add(Restrictions.eq("bookName", name));
		List<BookRegister> result=criteria.list();
		if (result==null || result.size()==0) {
			return null;
		}else{
			return result.get(0);
		}
	}
}
